<script type="text/javascript" src="http://www.12301.cc/js/jquery-1.8.0.min.js"></script>
<link type="text/css" rel="stylesheet" href="http://www.12301.cc/tpl/publish_coupons/css/publish_coupons.css" />
<link rel="stylesheet" href="http://www.12301.cc/css/common/www.12301.cc.global.css"/>
<script type="text/javascript" src="http://www.12301.cc/tpl/channels_confd/js/global.js"></script>



<div class="conmone" id="conmone">
	<ul id="tabHead" class="tabHead clearfix">
        <li class="profit">发布优惠券</li>
    </ul>
	<form id="conpu_form">
		<div class="coupons_con">
			<input type="hidden" name="action" value="coupon_create">
			<input type="hidden" name="id" class="id_id" value="">
			<div class="_dname">
				<span class="coupons_dname">名称：</span>
				<input type="text" name="coupon_name" class="coupons_title coupon_dname" value="">
			</div>
			<div class="_dname">
				<span class="coupons_dname">面额：</span>
				<input type="text" name="coupon_value" class="coupons_title coupon_num num_f" value="">
			</div>
			<div class="_dname"> 
				<span class="coupons_dname" id="counter-time">使用有效期：</span>
				<div class="coup_select">
					<input type="radio" name="e_type" value="1" class="coupons_che coupon_time" checked="checked" />
				</div>
				<!--<div class="conmone_time">
                
					<input type="text" data-t="bt" id="txtStartTime"  name="effective_start" data-msg="请选择时间段" onfocus="WdatePicker({minDate:'%y-%M-{%d}'})" class="texbettime" autocomplete="off"/>
					<span class="zhi">至</span>
					<input type="text" data-t="et" id="txtEndTime"  name="effective_end" data-msg="请选择时间段" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'txtStartTime\')}',maxDate:'2020-10-01'})"class="texendtime" autocomplete="off"/>
					<i class="calendarBtn c1"></i>
					<i class="calendarBtn c2"></i>
				</div>-->
                <div class="conmone_time pBox">
                    <div class="startbox"><input type="text" readonly id="txtStartTime" name="effective_start" value="" class="startDate"/><img src="http://www.12301.cc/tpl/publish_coupons/date/images/dateicon.png"/></div>
                    <div class="datetxt">至</div>
                    <div class="endtbox"><input type="text" readonly id="txtEndTime" name="effective_end" value=""  class="endDate"/><img src="http://www.12301.cc/tpl/publish_coupons/date/images/dateicon.png"/></div>	   		
                </div>
			
				<div class="coup_select">
					<label>
						<input type="radio" name="e_type" value="0" class="coupons_che coupon_today"  />
						<span class="coup_titile">获得优惠券当日有效</span>
					</label>
				</div>
			</div> 
			<div class="_dname">
				<span class="coupons_dname">自动发放：</span>
				<div class="conf_list">
					<ul class="selectlist_">
						<label><li><input class="check checkbox b1" name="auto_send" type="checkbox"  value="1">由系统自动发放</li></label>
					</ul>
				</div>
			</div>
			<div class="_dname">
				<span class="coupons_dname_t">适用产品：</span>
				<div class="seamles">
					<span class="select_btn btn_choose">选择</span>
					<input type="hidden"  name="pid" class="select_ic" value="">
					<input type="hidden" id="Text1" value="">
					<span class="ticket_title"></span>
				</div>
				<!-- <div class="seamlet">
					<p class="select_t">适用所有产品</p>
					<p class="select_t">选择部分产品时，最多列出两行产品，逗号隔开</p>
				</div> -->
			</div>
			<div class="_dname">
				<span class="coupons_dname"> 销售渠道：</span>
				<div class="conf_list">
					<ul class="selectlist">
						<label><li><input class="check checkbox a1" name="use_channel[]" type="checkbox" checked="checked" value="1">微信</li></label>
						<label><li><input class="check checkbox a2" name="use_channel[]" type="checkbox" value="2">二级店铺</li></label>
						<label><li><input class="check checkbox a3" name="use_channel[]" type="checkbox" value="3">自助机</li></label>
						<label><li><input class="check checkbox a7" name="use_channel[]" type="checkbox" value="4">会员卡</li></label>
						<!-- <span class="conf_tt">（可多选）</span> -->
					</ul>
				</div>
			</div>
			<div class="_dname">
				<span class="coupons_dname">消费限制：</span>
				<div class="coupos_limit">
					<span class="font">消费满</span>
					<input type="text" class="money_coupos num_g" name="condition" value="">
					<span class="font">&nbsp;元可用</span>
					
				</div>
			</div>
			<div class="_dname">
				<span class="coupons_dname">使用限制：</span>
				<div class="conf_list">
					<ul class="selectlist">
						<label><li><input class="check a4" name="use_limit" type="radio"  value="0">不限</li></label>
						<label><li><input class="check a5" name="use_limit" type="radio" checked="checked" value="1">一张</li></label>
						<label><li><input class="check a6" name="use_limit" type="radio" value="2">订票数</li></label>
					</ul>
				</div>
			</div>
			
			<span class="line"></span>
			<!-- <div class="_dname">
					<span class="coupons_dname">发行方式：</span>
					<select name="coupos_type" id="conSelect" class="coupons_se">
						<option value="1">领取</option>
						<option value="2">派发</option> 
					</select>
			</div> -->
			<div class="_dname"> 
				<span class="coupons_dname" >领取时间：</span>
				<!--<div class="conmone_time_">
					<input type="text" data-t="bt" id="txtStartTime_"  name="collect_startdate" data-msg="请选择时间段" onfocus="WdatePicker({minDate:'%y-%M-{%d}'})" class="texbettime_" autocomplete="off"/>
					<span class="zhi">至</span>
					<input type="text" data-t="et" id="txtEndTime_"  name="collect_enddate" data-msg="请选择时间段" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'txtStartTime_\')}',maxDate:'2020-10-01'})"class="texendtime_" autocomplete="off"/>
					<i class="calendarBtn c1_"></i>
					<i class="calendarBtn c2_"></i> 
				</div>-->
                <div class="conmone_time_ pBox">
                    <div class="startbox"><input type="text" id="txtStartTime_" readonly name="collect_startdate" value="" class="startDate"/><img src="http://www.12301.cc/tpl/publish_coupons/date/images/dateicon.png"/></div>
                    <div class="datetxt">至</div>
                    <div class="endtbox"><input type="text" id="txtEndTime_" readonly name="collect_enddate" value="" class="endDate"/><img src="http://www.12301.cc/tpl/publish_coupons/date/images/dateicon.png"/></div>	   		
                </div>
			</div>
			<div class="_dname">
				<span class="coupons_dname">发行数量：</span>
				<input type="text" class="coupons_title coupon_num_ticket num_h" name="nums" value="">
			</div>
			<div class="_dname">
				<span class="coupons_dname">限领张数：</span>
				<div>
					<label class="labela">
						<input type="text" class="label_ticke"  name="collect_limit" value="">
						<span class="label_ti">张/人</span>
					</label>
					<!-- <label class="labelb">
						<input type="radio" name="confirm_wx" value="1" class="confirm_wx">
						<input type="text" class="label_people" name="conf_day" value="">
						<span class="label_ti">张/天/人</span>
					</label>  -->
				</div>
			</div>
		</div>
	</form>
	<span class="save_btn">发布</span>
</div>
<div class="bgbox">	</div>
<div class="checkchoose_box " id="checkchoose_box">
		<div class="theme_top">
			<p class="ticket_name_ch">适用产品</p>
		</div>
		<div class="theme_select">
			<label class="labeld">
				<input type="radio" name="chose_" value="0" class="chose_all" checked="checked">
				<span class="theme_t">所有产品</span>
			</label>
			<label class="labeld">
				<input type="radio" name="chose_" value="1" class="chose_se" >
				<span class="theme_t">选择产品</span>
			</label> 
			<span class="chose_s">注:未选择产品则默认适用全部产品</span>
		</div>
		<div class="selectbox">
			<ul id="prods_list" class="ul_list">
				<ul id="selected_lnk_prods"></ul>
			</ul>
		</div>
		<div class="sereize">
			<div class="qunaer_select qunaer_type" id="qunaer_select">
				<input id="prodSearchInp" class="prodSearchInp"  type="text"></input>
				<i class="iconfont select_icon">&#xe633;</i>
				<ul class="prodList" id="prodList"></ul>
				<div class="searchmsg"><span class="no_seach">无结果</span></div>
				<input type="hidden"  id="lid_id" value=""/>
				<div class="qunaer_table">
					<div class="tbBox">	</div> 
				</div>
			</div>
			
			<div class="order_div" id="order_lili">
				<ul class="order_ul"></ul>
			</div>
		</div>
		<div class="btnbox">
			<span class="btn_base btn_cancels">取消</span>
			<span class="btn_base sure_s btn_sure_all" >确定</span>
		</div>
</div>
   <!--------日历引入js-------------->
    <link rel="stylesheet" href="http://www.12301.cc/tpl/publish_coupons/date/css/jquery.ui.css" type="text/css" />
	<script type="text/javascript" src="http://www.12301.cc/tpl/publish_coupons/date/js/jquery.ui.js"></script>
	<script type="text/javascript" src="http://www.12301.cc/tpl/publish_coupons/date/js/moment.min.js"></script>
	<script type="text/javascript" src="http://www.12301.cc/tpl/publish_coupons/date/js/stay.js"></script>
    <script language="javascript" src="http://www.12301.cc/tpl/publish_coupons/date/js/data.js"></script> 
   <!--------日历引入js end-------------->
<script type="text/javascript" src="http://www.12301.cc/tpl/prod_sale/js/class.js"></script>
<script type="text/javascript" src="http://wx.12301.cc/public/js/common/ajax.js"></script>
<script type="text/javascript" src="http://www.12301.cc/tpl/publish_coupons/js/publish_coupons.js"></script>
<script src="http://www.12301.cc/js/WdatePicker.js"></script>
<script id="list_template" type="text/template">
	<li class="list">
		<span class="title_list" title="{title}">
		{title}
		</span>
		<a class="rm" title="删除" href="javascript:;">X</a>
		<input type="hidden" name="lnkprods[]" value="{id}">
	</li>
</script>
<script>
 
var lnk_prods_opt = {
	
    showDialog : function(){
		var objtr = $(".select_ic").val();
		if(objtr=="0"){
			$(".chose_all").attr("checked","checked");
			$(".chose_s").hide();
		}else{
			$(".chose_se").attr("checked","checked");
			$(".chose_s").show();
		}
        var al=$('input:radio[name="chose_"]:checked').val();//判断适用全部产品还是个别产品
		if(al=="0"){
			$(".select_ic").val("0");
			$(".sereize").hide();
		}
		else{
		//console.log(objtr)
		//var lids = $("#Text1").val();
		var  tpl = $("#list_template").html();
		$("#selected_lnk_prods").empty();
		var le = objtr.split(",")
		var len = le.length;
		for(var i=0;i<len;i++)
		 {
			var id = $(le)[i];
			//var id = lids;
			var data = {pid:id};
			var url = "/call/jh_coupon.php?action=coupon_prods";
			PFT.Ajax({
				url : url,
				type : "GET",
				dataType : "json",
				data : data
			},function(res){
				var lists = res.list;
				for(var i in lists){
					var t = lists[i]["pid"];
					var ltitle = lists[i]["ltitle"];
					var ttitle = lists[i]["ttitle"];
					var k = ltitle+"-"+ttitle;
					$("#selected_lnk_prods").after(template(tpl, {id:t,title:k}));
				}
				
				//$("#selected_lnk_prods").after(template(tpl, {id:id,title:k}));
			})
		 }
		
		}
    },
	chlick : function(){
				var len=$(".list").length;
				if(len>0){
					PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">抱歉无法再添加产品</p>');
					return false;
				}
				var  tpl = $("#list_template").html();
				$("#selected_lnk_prods").empty();
					//var k = $(this).text();
					var kk = $(this).attr("title");
					var tttile = $(this).attr("tttile");
					var k = kk+"-"+tttile;
					var lig = $(".ul_list li").length;
					var id = $(this).attr("data-id");
					if(lnk_prods_opt.check(id)){
						  $("#selected_lnk_prods").after(template(tpl, {id:id,title:k}));
					}
					 else{
						PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">您已添加了同样的产品</p>');
					 }	
					
			},
	check : function(id){
		var re = true;
		$(".ul_list li input").each(function(){
			var data = $(this).val();
				if(id==data){
					re = false;
				}
		})
		return re;
	},
	clikkk :function(){
		var sel="";
		var ad=$(".list").length;
		var all = $
		if(ad=="0"){
			$(".select_ic").val("0") 
		}else{
		//console.log(ad)
			$(".ul_list li input").each(function(){		
				//sel+= ","+$(this).val();  
				//var len=$(".list").length;
				//console.log(len)
				var sel = Number($(this).val()); 
				$(".select_ic").val(sel)    
				//console.log(sel)
			})
		}
		
	},
	num_bluf :function(e){
		var targe = $(e.currentTarget);
		var val = targe.val();
		//console.log(val)
		if(!val || !PFT_GLOBAL.U.isNum(val)){
			targe.val("");
			PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">面额输入必须为大于0的数字</p>');
			return false;
		}
		
	},
	num_blug :function(e){
		var target = $(e.currentTarget);
		var val = target.val();
		if(!val || !PFT_GLOBAL.U.isNum(val)){
			target.val("");
			PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">消费限制金额输入必须为大于0的数字</p>');
			return false;
		}
		
	},
	num_bluh :function(e){
		var targeh = $(e.currentTarget);
		var val = targeh.val();
		if(!val || !PFT_GLOBAL.U.isPositiveNum(val)){
			targeh.val("");
			PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">发行数量输入必须为大于0的整数</p>');
			return false;
		}
		
	},
	add_list : function(){
		lnk_prods_opt.clikkk();
		var title_ = $(".title_list").attr("title");
		$("#checkchoose_box").animate({"top":-80});			
		$(".bgbox,#checkchoose_box").hide();
		var s = $(".select_ic").val();
		if (s.substr(0,1)==',') 
		s=s.substr(1);
		$(".select_ic").val(s)
		$(".ul_list li").each(function(){
			$(this).remove();
		})
		$(".ticket_title").html(title_);
	}
};
function template(tpl, val){
				return tpl.replace(/\{(\w+)\}/g, function(m,i){
					if(val[i]) {
						return val[i];
					} else {
						return '';
					}
				})
			};
$(".rm").live('click',function(e){
	$(this).parent().remove();
	var v = $(this).next('input').val();
	$("input[name='lnkprods'][value='"+v+"']").remove();
})
$(".chose_all").live("click",function(){
	$(".select_ic").val("0");
	$(".list").remove();
	$(".chose_s").hide();
	$(".sereize").hide();

});
$(".chose_se").live("click",function(){
	$(".chose_s").show();
	$(".sereize").show();
	var objtr = $(".select_ic").val();
	var  tpl = $("#list_template").html();
		$("#selected_lnk_prods").empty();
		var le = objtr.split(",")
		var len = le.length;
		for(var i=0;i<len;i++)
		 {
			var id = $(le)[i];
			//var id = lids;
			var data = {pid:id};
			var url = "/call/jh_coupon.php?action=coupon_prods";
			PFT.Ajax({
				url : url,
				type : "GET",
				dataType : "json",
				data : data
			},function(res){
				var lists = res.list;
				for(var i in lists){
					var t = lists[i]["pid"];
					var ltitle = lists[i]["ltitle"];
					var ttitle = lists[i]["ttitle"];
					var k = ltitle+"-"+ttitle;
					$("#selected_lnk_prods").after(template(tpl, {id:t,title:k}));
				}
				
				//$("#selected_lnk_prods").after(template(tpl, {id:id,title:k}));
			})
		 }

})
var sel="";
$(".btn_sure_allk").on('click',function(e){
	$(".ul_list li input").each(function(i){		
			
			sel+= $(this).val()+",";  
			//$(".select_ic").val(null);
			$(".select_ic").val(sel)
			$("#checkchoose_box").animate({"top":-80});			
			$(".bgbox,#checkchoose_box").hide();
			//$(this).val(null);
			
		})
}) 
jQuery(document).ready(function($){
	 $(".btn_choose").on('click', lnk_prods_opt.showDialog);
	 //$(".chose_all").on('click', lnk_prods_opt.chose_all);//全部产品
	 //$(".chose_se").on('click', lnk_prods_opt.chose_se);//选择产品
     $(".add_list").live('click', lnk_prods_opt.chlick);
     $(".btn_sure_all").live('click', lnk_prods_opt.add_list);
     $(".num_f").on('blur', lnk_prods_opt.num_bluf);
     $(".num_g").on('blur', lnk_prods_opt.num_blug);
     $(".num_h").on('blur', lnk_prods_opt.num_bluh);
		var url = window.location.href;
		var lids = url.split('=')[1];
		$("#Text1").val(lids);
		if(lids!=undefined){
		$(".save_btn").text("保存")
		$(".id_id").val(lids);
		var data = {id:lids};
		var url = "/call/jh_coupon.php?action=coupon_list";
			PFT.Ajax({
				url : url,
				type : "GET",  
				dataType : "json",
				data : data
			},function(res){ 
				var lists = res.list;
				for(var i in lists){
					$(".money_coupos").val((lists[i]["condition"] / 100).toFixed(2));//消费限额
					var limit_use =lists[i]["limit_use"];//使用限制 0 不限 1 一次1张 2 随门票总数
					//console.log(limit_use) 
						if(limit_use=="0"){
							$(".a4").attr("checked","checked");
						}
						if(limit_use=="1"){
							$(".a5").attr("checked","checked");
						}
						if(limit_use=="2"){
							$(".a6").attr("checked","checked");
						}
					$("#txtStartTime_").val(lists[i]["collect_startdate"]);//领取时间开始
					$("#txtEndTime_").val(lists[i]["collect_enddate"]);//领取时间结束
					$(".label_ticke").val(lists[i]["collect_limit"]);//限领张数
					$(".coupon_num_ticket").val(lists[i]["nums"]);//发现数量 -1表示不限
					$(".coupon_dname").val(lists[i]["coupon_name"]);//票名
					$(".coupon_num").val((lists[i]["coupon_value"] / 100).toFixed(2));//面额
					$("#txtStartTime").val(lists[i]["use_startdate"]);//有效期开始
					$("#txtEndTime").val(lists[i]["use_enddate"]);//有效期结束
					if(Number(lists[i]["effective_type"])>2){
						var effective_type =Number(lists[i]["effective_type"])-2;//需要减2   才能得到  有效期判断类型0 领取当天有效 1设置时间段
						
					}else{
						var effective_type =Number(lists[i]["effective_type"]);
					
					
					}
					
					var effective_t =Number(lists[i]["effective_type"]);   //大于1的值 系统自动发送 勾选
					if(effective_t>1){
						$(".b1").attr("checked","checked");
					}
					//console.log(effective_type)
					if(effective_type=="1"){
						$(".coupon_time").attr("checked","checked");
					}
					else{
						$(".coupon_today").attr("checked","checked");
						$(".texbettime").val("");
						$(".texendtime").val("");
					}
					$(".select_ic").val(lists[i]["pid"]);//适用产品
					$(".select_ic").attr("time",lists[i]["pid"]);//适用产品
					var channel =lists[i]["channel"];//销售渠道 0 不限 1 微信 2 二级店铺 3自助机
					var channel_len = channel.split(",")
					var len = channel_len.length;
					for(var i=0;i<len;i++)
					 {
						var id = $(channel_len)[i];
						if(id=="1"){
							$(".a1").attr("checked","checked");
						}
						if(id=="2"){
							$(".a2").attr("checked","checked");
						}
						if(id=="3"){
							$(".a3").attr("checked","checked");
						}
						if(id=="4"){
							$(".a7").attr("checked","checked");
						}

					 }
				}
			})
		}
});

</script>
<script>
(function(){
	var h=$(window).height(); 
	var w=$(window).width(); 
	$(".btn_choose").on("click",function(e){
		var target = $(e.currentTarget);
		var tpl = $("#list_template").html();
		var atpl = $("#list_tema").html();
		var teacl = target.attr("data");
		var tlid = target.attr("lid");
		$(".terminal_add").attr("add",teacl);
		$(".terminal_add").attr("lid",tlid);
		var ttitle = target.attr("title");
		$(".ticket_name_ch").text(ttitle);
		$(".bgbox").show();
		$("#checkchoose_box").show();
		$("#checkchoose_box").animate({"top":80});
		$(".bgbox").css("height",h);
		$(".bgbox").css("width",w); 
		
		})
		
		$(".btn_cancels,.close_btn").on("click",function(e){
			$(".ul_list li").each(function(){
				$(this).remove();
				
				 
				
			})
			var target = $(e.currentTarget);
			$("#checkchoose_box").animate({"top":-80});		 	
			$(".bgbox,#checkchoose_box").hide();				
		}); 
})();

 setTimeout(function () { 
       var 	pid = $(".select_ic").attr("time"),
			data = {
				action : "coupon_prods",
				pid : pid
			}
	   PFT.Ajax({
			url : "call/jh_coupon.php",
				type : "GET",
				dataType : "json",
				data : data
		},function(res){
			var lists = res.list;
				ttitle = lists[0]["ttitle"];
				ltitle = lists[0]["ltitle"];
			$(".ticket_title").html(ltitle+" "+ttitle);
		})
    }, 1000);

</script>
 

